home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / AMIGA / TTYMOUSE.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  6KB  |  290 lines

  1. /*
  2.  * Name:    MG 2a
  3.  *        Commodore Amiga mouse handling 
  4.  * Created:    Distant past
  5.  * Last edit:    28-Nov-87  mic@emx.cc.utexas.edu
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #undef    TRUE
  11. #undef    FALSE
  12. #include "def.h"
  13. #ifndef    NO_MACRO
  14. #include "macro.h"
  15. #endif
  16.  
  17. extern    int    ttmouse();
  18. extern    int    forwline();
  19. extern    int    forwchar();
  20. extern    int    setmark();
  21. extern    int    isetmark();
  22.  
  23. /* stuff for go-to-window-and-do-it functions */
  24. extern    int    reposition();
  25. extern    int    delfword();
  26. extern    int    killline();
  27. extern    int    forwdel();
  28. extern    int    justone();
  29. extern    int    killregion();
  30. extern    int    yank();
  31. extern    int    forwpage();
  32. extern    int    backpage();
  33. extern    int    splitwind();
  34. extern    int    delwind();
  35. extern    int    gotobob();
  36. extern    int    gotoeob();
  37. extern    int    enlargewind();
  38. extern    int    shrinkwind();
  39.  
  40. /*
  41.  * Handle the mouse click that's been passed by ttgetc() and position
  42.  * dot where the user pointed at.  If this is the same position
  43.  * where the user pointed the last time, set the mark, whether or
  44.  * not this is a true double-click. This isn't a true double-click,
  45.  * but it does most of what we want.
  46.  */
  47.  
  48. static USHORT    oldrow = HUGE, oldcol = HUGE;    /* last mouse click    */
  49. static USHORT    newrow, newcol;            /* next mouse click    */
  50.  
  51. amigamouse(f, n)
  52. {
  53.     if (!dottomouse())            /* sets newrow, newcol    */
  54.         return (FALSE);
  55.     if ((newrow == oldrow) && (newcol == oldcol))
  56.         setmark(FFRAND, 1);        /* double-click        */
  57.     oldrow = newrow;                /* save state        */
  58.     oldcol = newcol;
  59.     return (TRUE);
  60. }
  61.  
  62. /*
  63.  * Recenter on selected line
  64.  */
  65. mreposition(f, n)
  66. {
  67.     if (!dottomouse())
  68.         return (FALSE);
  69.     return (reposition(f, n));
  70. }
  71.  
  72. /*
  73.  * Delete word after selected char
  74.  */
  75. mdelfword(f, n)
  76. {
  77.     if (!dottomouse())
  78.         return (FALSE);
  79.     return (delfword(f, n));
  80. }
  81.  
  82. /*
  83.  * Move to selection, kill line
  84.  */
  85. mkillline(f, n)
  86. {
  87.     if (!dottomouse())
  88.         return (FALSE);
  89.     return (killline(f, n));
  90. }
  91.  
  92. /*
  93.  * Move to selection, kill word
  94.  */
  95. mforwdel(f, n)
  96. {
  97.     if (!dottomouse())
  98.         return (FALSE);
  99.     return (forwdel(f, n));
  100. }
  101.  
  102. /*
  103.  * Move to selection, kill line
  104.  */
  105. mdelwhite(f, n)
  106. {
  107.     if (!dottomouse())
  108.         return (FALSE);
  109.     return (justone(f, n));
  110. }
  111.  
  112. /*
  113.  * Set mark, move to selection, kill region.
  114.  */
  115. mkillregion(f, n)
  116. {
  117.     register struct LINE *p_old;
  118.     register short    o_old;
  119.  
  120.     p_old = curwp->w_markp;        /* Save old mark */
  121.     o_old = curwp->w_marko;
  122.     isetmark();                /* and set current one */
  123.     if (!dottomouse()) {
  124.         curwp->w_markp = p_old;    /* Oops - put mark back */
  125.         curwp->w_marko = o_old;
  126.         return (FALSE);
  127.         }
  128.     return (killregion(f, n));
  129. }
  130.  
  131. /*
  132.  * Move to selection, yank kill buffer
  133.  */
  134. myank(f, n)
  135. {
  136.     if (!dottomouse())
  137.         return (FALSE);
  138.     return (yank(f, n));
  139. }
  140.  
  141. /*
  142.  * Select window pointed to by mouse, then scroll down
  143.  */
  144.  
  145. mforwpage(f, n)
  146. {
  147.     if (!dottomouse())
  148.         return (FALSE);
  149.     return (forwpage(f, n));
  150. }
  151.  
  152. /*
  153.  * Select buffer, scroll page down
  154.  */
  155. mbackpage(f, n)
  156. {
  157.     if (!dottomouse())
  158.         return (FALSE);
  159.     return (backpage(f, n));
  160. }
  161.  
  162. /*
  163.  * Select the window, split it.
  164.  */
  165. msplitwind(f, n)
  166. {
  167.     if (!dottomouse())
  168.         return (FALSE);
  169.     return (splitwind(f, n));
  170. }
  171.  
  172. /*
  173.  * Select the buffer, delete it.
  174.  */
  175. mdelwind(f, n)
  176. {
  177.     if (!dottomouse())
  178.         return (FALSE);
  179.     return (delwind(f, n));
  180. }
  181.  
  182. /*
  183.  * Select window, goto beginning of buffer
  184.  */
  185. mgotobob(f, n)
  186. {
  187.     if (!dottomouse())
  188.         return (FALSE);
  189.     return (gotobob(f, n));
  190. }
  191.  
  192. /*
  193.  * Select window, go to end of buffer
  194.  */
  195. mgotoeob(f, n)
  196. {
  197.     if (!dottomouse())
  198.         return (FALSE);
  199.     return (gotoeob(f, n));
  200. }
  201.  
  202. /*
  203.  * Select window, enlarge it.
  204.  */
  205. menlargewind(f, n)
  206. {
  207.     if (!dottomouse())
  208.         return (FALSE);
  209.     return (enlargewind(f, n));
  210. }
  211.     
  212. /*
  213.  * Select window, shrink it.
  214.  */
  215. mshrinkwind(f, n)
  216. {
  217.     if (!dottomouse())
  218.         return (FALSE);
  219.     return (shrinkwind(f, n));
  220. }
  221.  
  222. /*
  223.  * Utility routine to move dot to where the user clicked.  If in
  224.  * mode line, chooses that buffer as the one to work on.
  225.  */
  226.  
  227. static dottomouse()
  228. {
  229.     register WINDOW *wp;
  230.     register int    dot;
  231.     register int    col;
  232.     register int    c;
  233.     int        getkey();
  234.  
  235. #ifndef    NO_MACRO
  236.     if (inmacro)
  237.         return FALSE;    /* can't record mouse clicks */
  238. #endif
  239.  
  240.     /* read the next 2 characters to get the col, row info, using
  241.      * getkey() to record them (or re-read them if in a macro).
  242.      */
  243.     newcol = getkey(FALSE) - M_X_ZERO;
  244.     newrow = getkey(FALSE) - M_Y_ZERO;
  245.  
  246. #ifndef    NO_MACRO
  247.     if (macrodef) {        /* menu picks can't be practically recorded */
  248.         ewprintf("Can't record mouse clicks");
  249.         return (FALSE);
  250.     }
  251. #endif
  252.  
  253.     /* find out which window was clicked in                */
  254.     for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
  255.         if ((newrow >= wp->w_toprow) && 
  256.             (newrow <= (wp->w_toprow + wp->w_ntrows)))
  257.             break;
  258.  
  259.     if (wp == NULL)                /* echo line        */
  260.         return (ABORT);
  261.     else if (newrow == wp->w_toprow + wp->w_ntrows) {/* mode line */
  262.         curwp = wp;            /* just change buffer     */
  263.         curbp = wp->w_bufp;
  264.     } else {
  265.         /* move to selected window, move dot to top left    */
  266.         curwp = wp;
  267.         curbp = wp->w_bufp;
  268.         curwp->w_dotp = wp->w_linep;
  269.         curwp->w_doto = 0;
  270.  
  271.         /* go forward the correct # of lines         */
  272.         forwline(FFRAND, newrow - curwp->w_toprow);
  273.     
  274.         /* go forward the correct # of characters    */
  275.         /* need to count them out because of tabs    */
  276.         col = dot = 0;
  277.         while ((col < newcol) && (dot < llength(curwp->w_dotp))) {
  278.             c = lgetc(curwp->w_dotp, dot++);
  279.             if (c == CCHR('I'))
  280.                 col |= 0x07;
  281.             else if (ISCTRL(c) != FALSE)
  282.                 ++col;
  283.             ++col;
  284.         }
  285.         if (col > newcol) dot--;    /* back up to tab/ctrl char */
  286.         forwchar(FFRAND, dot);
  287.     }
  288.     return (TRUE);
  289. }
  290.